<template>
  <div class="weather">
    <div class="input">
      <input
        type="text"
        placeholder="请输入你想查询的城市"
        v-model="newCity"
        @keyup.enter="changeCity(newCity)"
      >
      <button @click="changeCity(newCity)">查询</button>
    </div>
    <Card
      :city="city"
      :future="future"
      :realtime="realtime"
    />
  </div>
</template>

<script>
import { useWeather } from '@/hooks'
import { toRefs, ref } from 'vue'
import Card from './Card'
export default {
  name: 'Weather',
  components: {
    Card
  },
  setup () {
    const { state, changeCity } = useWeather()
    const newCity = ref('')
    return {
      newCity,
      ...toRefs(state),
      changeCity
    }
  }
}

</script>

<style scoped>
.weather {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.input {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  margin-bottom: 8px;
}
input {
  width: 60vw;
  font-size: 20px;
  padding: 0 8px;
  font-weight: 550;
  margin-right: 4px;
}
</style>
